package com.ygxsk.carhome.views;

import android.content.Context;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.LogUtils;
import com.lxj.xpopup.core.BottomPopupView;
import com.lxj.xpopup.util.XPopupUtils;
import com.park.keyboard.OnInputChangedListener;
import com.park.keyboard.PopupKeyboard;
import com.park.keyboard.view.InputView;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.constant.ConstantSign;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-11-17  17:20
 * @Description:车牌号的录入信息的弹窗 通用的
 */
public class CarCardPopu extends BottomPopupView {

    private PopupKeyboard mPopupKeyboard;
    //软键盘的内容
    private InputView mInputView;

    //因为通用界面，标志从哪个页面过来；
    private int extra_jumpfrom_where;

    public CarCardPopu(@NonNull Context context) {
        super(context);
    }

    public CarCardPopu(@NonNull Context context, int _flag) {
        super(context);
        this.extra_jumpfrom_where = _flag;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.popucarcard;
    }

    @Override
    protected void onCreate() {
        super.onCreate();

        //直接填充布局的内容
        //取消按钮
        TextView btn_dialog_search_cancel = (TextView) this.findViewById(R.id.btn_dialog_input_cancel);
        //确定按钮
        TextView btn_dialog_search_decide = (TextView) this.findViewById(R.id.btn_dialog_input_decide);

        //键盘布局
        mInputView = (InputView) this.findViewById(R.id.input_view);

        //做键盘绑定
        // 创建弹出键盘
        mPopupKeyboard = new PopupKeyboard(this.getContext());
        // 弹出键盘内部包含一个KeyboardView，在此绑定输入两者关联。
        mPopupKeyboard.attach(mInputView, this.getActivity());

        // 隐藏确定按钮? 不要隐藏
//        mPopupKeyboard.getKeyboardEngine().setHideOKKey(mHideOKKey);

        // KeyboardInputController提供一个默认实现的新能源车牌锁定按钮
//        mPopupKeyboard.getController()
//                .setDebugEnabled(true)
//                .setSwitchVerify(verifyCheckButton.isChecked())//是否是新能源
//                .bindLockTypeProxy(new KeyboardInputController.ButtonProxyImpl(lockTypeButton) {
//                    @Override
//                    public void onNumberTypeChanged(boolean isNewEnergyType) {
//                        super.onNumberTypeChanged(isNewEnergyType);
//                        if (isNewEnergyType) {
//                            lockTypeButton.setTextColor(getResources().getColor(android.R.color.holo_green_light));
//                        } else {
//                            lockTypeButton.setTextColor(getResources().getColor(android.R.color.black));
//                        }
//                    }
//                });

        mPopupKeyboard.getController().addOnInputChangedListener(new OnInputChangedListener() {
            @Override
            public void onChanged(String number, boolean isCompleted) {
                if (isCompleted) {
                    mPopupKeyboard.dismiss(CarCardPopu.this.getActivity());
                }
            }

            @Override
            public void onCompleted(String number, boolean isAutoCompleted) {
                mPopupKeyboard.dismiss(CarCardPopu.this.getActivity());
            }
        });

        //

    }


    @Override
    protected void onShow() {
        super.onShow();

        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "界面弹窗 弹出");

        if (mInputView != null) {
            // 默认选中第一个车牌号码输入框
            mInputView.performFirstFieldView();
        }

    }


    @Override
    public void onDestroy() {

        //LogUtils.d(ConstantSign.LOGCAT_NOMAL + "弹窗--弹窗--弹窗onDestroy--onDestroy---onDestroy--onDestroy--onDestroy");

//        if (evaluate_wade_list_outSide != null && !evaluate_wade_list_outSide.isEmpty()) {
//
//            for (EvaluateWadeDataInfo evaluateWadeDataInfo : evaluate_wade_list_outSide) {
//                evaluateWadeDataInfo.setChecked(false);
//            }
//
//            if (evaluateWadeDataInfoAdapter != null) {
//                evaluateWadeDataInfoAdapter.notifyDataSetChanged();
//            }
//
//        }

        super.onDestroy();

    }


    @Override
    protected boolean onBackPressed() {

//        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "拦截 弹出弹窗的  返回事件");
//        CommUtils.checkDialog(alertViewDialogSure);
//        if (mDatasResources!=null&&!mDatasResources.isEmpty()){
//        }

        return super.onBackPressed();
    }


    @Override
    protected int getMaxHeight() {
        return (int) (XPopupUtils.getScreenHeight(getContext()) * .6f);
    }

}
